package com.yz.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * 描述：
 **/
public class RabbitmqPro {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("111.229.85.126");
        connectionFactory.setVirtualHost("/");
        connectionFactory.setPort(5671);
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        for (int i=0;i<5;i++) {
            channel.basicPublish("", "test", null, ("hello word!"+i).getBytes());
            TimeUnit.SECONDS.sleep(1);
        }
        channel.close();
        connection.close();
    }
}
